﻿using Power.Models;
using Power.View.Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Power.ViewModel.Report
{
    /// <summary>
    /// 工点工作量表
    /// </summary>
    public class PointWorkLoadTableViewModel : ReportTableBase
    {
        public List<WorkingTableData> Data { get; set; }
        private PointWorkLoadTable model;
        public PointWorkLoadTableViewModel(PointWorkLoadTable model)
        {
            this.model = model;
            Data = CreateEntity<WorkingTableData>(5);
            Init();
        }

        /// <summary>
        /// 动态创建测试数据
        /// </summary>
        /// <param name="subCount"></param>
        /// <returns></returns>
        public List<T> CreateEntity<T>(int count)
        {
            var list = new List<T>();

            for (int i = 0; i < count; i++)
            {
                var obj = Activator.CreateInstance(typeof(T));

                var type = obj.GetType();
                var props = type.GetProperties();
                foreach (var item in props)
                {
                    if (item.PropertyType == typeof(int))
                    {
                        item.SetValue(obj, 1);
                    }
                    else if (item.PropertyType == typeof(string))
                    {
                        item.SetValue(obj, "2");
                    }
                }
                list.Add((T)obj);
            }

            return list;
        }
        public void Init()
        {
            var color1 = new SolidColorBrush(Color.FromRgb(0, 0, 255));
            var color2 = new SolidColorBrush(Color.FromRgb(255, 255, 0));
            var color3 = new SolidColorBrush(Color.FromRgb(255, 102, 0));
            var color4 = new SolidColorBrush(Color.FromRgb(255, 0, 0));

            //Row = Data.Count() + 4;
            Row = Data.Count() + 3;
            Column = 6;

            var table = this.model.table;

            for (int i = 0; i < Row; i++)
            {
                table.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });

            }
            for (int i = 0; i < Column; i++)
            {
                table.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(100) });
            }

            //画标题
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < Column; j++)
                {
                    DrawColumnSpanCell(table, i, j, "工点工作量表", Column, 0, 0);


                    DrawRowSpanCell(table, i, j, "序号", 2, 1, 0);
                    DrawRowSpanCell(table, i, j, "片区代码", 2, 1, 1);
                    DrawRowSpanCell(table, i, j, "区块代码", 2, 1, 2);
                    DrawRowSpanCell(table, i, j, "工点名称", 2, 1, 3);


                    DrawCell(table, i, j, "管段数量", 1, 4);
                    DrawCell(table, i, j, "检测长度", 1, 5);
                    DrawCell(table, i, j, "段", 2, 4);
                    DrawCell(table, i, j, "m", 2, 5);

                    
                }
            }

            //画内容
            for (int i = 3; i < Data.Count+3; i++)
            {
                var item = Data[i-3];
                DrawCell(table, i, 0, item.Order.ToString(), i, 0);
                DrawCell(table, i, 1, item.AreaCode.ToString(), i, 1);
                DrawCell(table, i, 2, item.BlockCode.ToString(), i, 2);
                DrawCell(table, i, 3, item.WorkingName.ToString(), i,3);
                DrawCell(table, i, 4, item.PipNum.ToString(), i, 4);
                DrawCell(table, i, 5, item.DetectLen.ToString(), i, 5);
            }

            //合计
            //DrawCell(table, Row - 1, 0, "合计", Row - 1, 0);
            //DrawCell(table, Row - 1, 1, "-", Row - 1, 1);
            //DrawCell(table, Row - 1, 2, "-", Row - 1, 2);
            //DrawCell(table, Row - 1, 3, "-", Row - 1, 3);
            //DrawCell(table, Row - 1, 4, Data.Sum(p=> p.PipNum).ToString(), Row - 1, 4);
            //DrawCell(table, Row - 1, 5, Data.Sum(p => p.DetectLen).ToString(), Row - 1, 5);


            //补边框
            DrawBorder(table);
        }
    }
}
